home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / compute / 1988_02 / wrimage.asm < prev    next >
Assembly Source File  |  1987-09-22  |  7KB  |  266 lines

  1. ; TEXT.ASM Assembly routines for Color Graphics Adapter text printing.
  2. ;          Used by WRIMAGE.C and written by John W. Ratcliff
  3. ;          Copyright (c) 1987 Compute!
  4.  
  5. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  6. _TEXT   ENDS
  7. CONST   SEGMENT  WORD PUBLIC 'CONST'
  8. CONST   ENDS
  9. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  10. _BSS    ENDS
  11. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  12. _DATA   ENDS
  13. DGROUP  GROUP   CONST,  _BSS,   _DATA
  14.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  15.  
  16.  
  17.  
  18. _DATA   SEGMENT
  19. _sec    db      0
  20. _hsec   db      0
  21. durat   dw      0
  22. start   dw      0
  23. x       db      0
  24. y       db      0
  25. x1      db      0
  26. x2      db      0
  27. y1      db      0
  28. y2      db      0
  29. col     db       0, 1, 9, 3, 11, 4, 12, 2, 10, 5, 13, 6, 14, 8, 7, 15
  30. ytab    dw  0, 160, 320, 480, 640, 800, 960, 1120, 1280, 1440
  31.         dw  1600, 1760, 1920, 2080, 2240, 2400, 2560, 2720, 2880, 3040
  32.         dw  3200, 3360, 3520, 3680, 3840, 4000
  33. _DATA   ENDS
  34.  
  35.         public  _tprint,_sec,_hsec,_setmode
  36.         public  _getime,_keystat,_flushk,_cursoff
  37.         public  _sound,_sound2
  38.  
  39. _TEXT   SEGMENT
  40.  
  41.  
  42. _setmode proc   near
  43. ; This routine set the graphics mode as specified
  44. ; by the BIOS interrupt 10h function 0
  45. ; al contains the video mode
  46. ; Modes are as follows:
  47. ;  0    40x25   Black and White text
  48. ;  1    40x25   Color text
  49. ;  2    80x25   Black and White text
  50. ;  3    80x25   Color text
  51. ;  4    320x200 Color graphics
  52. ;  5    320x200 Black and White graphics
  53. ;  6    640x200 Black and White graphics
  54. ;  7            mono graphics
  55. ;  9    TANDY MODE GRAPHICS
  56. ;  13   320x200 16 color EGA graphics
  57. ;  14   640x200 16 color EGA graphics
  58. ;  16   640x350 16 color EGA graphics
  59.         push    bp
  60.         mov     bp,sp
  61.         mov     ax,[bp+4]
  62.         mov     ah,0
  63.         int     10h
  64.         pop     bp
  65.         ret
  66. _setmode endp
  67.  
  68. _sound   proc    near
  69. ; sound(tone,duration)
  70.         push    bp
  71.         mov     bp,sp
  72.         mov     ax,[bp+6]
  73.         mov     durat,ax
  74.         mov     bx,[bp+4]
  75.         mov     al,10110110b
  76.         out     43h,al
  77.         mov     ax,bx
  78.         out     42h,al
  79.         mov     al,ah
  80.         out     42h,al
  81.         in      al,61h
  82.         or      al,3
  83.         out     61h,al
  84.         mov     bl,al
  85.         mov     ah,00h
  86.         int     1ah     ; get clock count
  87.         mov     start,dx
  88. snd0:   mov     ah,00
  89.         int     1ah
  90.         sub     dx,start
  91.         cmp     dx,durat
  92.         jl      snd0
  93.         mov     al,bl
  94.         and     al,0fch
  95.         out     61h,al
  96.         pop     bp
  97.         ret
  98. _sound   endp
  99.  
  100.  
  101.  
  102. _sound2  proc    near
  103. ; sound(tone,duration)
  104.         push    bp
  105.         mov     bp,sp
  106.         mov     cx,[bp+6]
  107.         mov     bx,[bp+4]
  108.         call    _sounder
  109.         pop     bp
  110.         ret
  111. _sound2  endp
  112.  
  113. _sounder proc    near
  114. ; bx register contains the tone
  115. ; cx contains the duration
  116.         mov     al,10110110b
  117.         out     43h,al
  118.         mov     ax,bx
  119.         out     42h,al
  120.         mov     al,ah
  121.         out     42h,al
  122.         in      al,61h
  123.         or      al,3
  124.         out     61h,al
  125.         mov     bl,al
  126.  
  127. snd20:  nop
  128.         nop
  129.         nop
  130.         nop
  131.         loop    snd20
  132.  
  133.  
  134.         mov     al,bl
  135.         and     al,0fch
  136.         out     61h,al
  137.         ret
  138. _sounder endp
  139.  
  140.  
  141. _tprint  proc    near
  142.  
  143. ; This routine will cause a text print. the format of the call is
  144. ; as follows:
  145. ; tprint(x,y,l,bc,fc,text)
  146.  
  147. ; x is the x location on the screen
  148. ; y is the y location on the screen
  149. ; l is the length to be output (padded on the right with spaces to length)
  150. ; is length is passed as zero then only the string will be output.
  151. ; bc is the background color 0-15
  152. ; fc is the foreground color 0-15
  153. ; text is the pointer to the text you wish to output.
  154.  
  155.         push    bp
  156.         mov     bp,sp
  157.         push    es
  158.         mov     ax,0b800h
  159.         mov     es,ax           ; es addresses the screen ram
  160.         mov     ax,[bp+4]
  161.         shl     ax,1            ; times two
  162.         mov     bx,[bp+6]       ; get the y location
  163.         shl     bx,1            ; times two for word boundaries
  164.         mov     si,ytab[bx]             ; multiply by 160
  165.         add     si,ax           ; now ax has offset into screen ram
  166.         mov     cx,[bp+8]       ; cx contains the length
  167.         mov     bx,[bp+10]      ; background color
  168.         shl     bl,1
  169.         shl     bl,1
  170.         shl     bl,1
  171.         shl     bl,1            ; moved to high nibble
  172.         mov     ax,[bp+12]
  173.         mov     bh,al           ; foreground color goes into bl
  174.         or      bh,bl           ; now the atribute byte in in bl
  175.         mov     di,[bp+14]      ; offset to text pointer in di
  176.         mov     ch,0            ; counter for number of chars done
  177. tp0:    mov     bl,ds:[di]      ; get character
  178.         cmp     bl,0
  179.         je      tpdn            ; text print finished
  180.         mov     dx,03dah
  181. rtr:    in      al,dx
  182.         sar     al,1
  183.         jc      rtr
  184. rtr1:   in      al,dx
  185.         sar     al,1
  186.         jnc     rtr1
  187.         mov     es:[si],bl
  188.         inc     si
  189. rtr0:   in      al,dx
  190.         sar     al,1
  191.         jc      rtr0
  192. rtr2:   in      al,dx
  193.         sar     al,1
  194.         jnc     rtr2
  195.         mov     es:[si],bh
  196.         inc     si
  197.         inc     di
  198.         inc     ch
  199.         jmp     tp0
  200. tpdn:   cmp     ch,cl
  201.         jge     tpdn0
  202.         sub     cl,ch
  203.         mov     ch,0
  204.         mov     bl,20h
  205.  
  206. tpd:    mov     dx,03dah
  207. rtr3:   in      al,dx
  208.         sar     al,1
  209.         jc      rtr3
  210. rtr4:   in      al,dx
  211.         sar     al,1
  212.         jnc     rtr4
  213.         mov     es:[si],bl
  214.         inc     si
  215. rtr5:   in      al,dx
  216.         sar     al,1
  217.         jc      rtr5
  218. rtr6:   in      al,dx
  219.         sar     al,1
  220.         jnc     rtr6
  221.         mov     es:[si],bh
  222.         inc     si
  223.         loop    tpd
  224. tpdn0:  pop     es
  225.         pop     bp
  226.         ret
  227.  
  228. _tprint  endp
  229.  
  230.  
  231. _flushk   proc    near
  232.         mov     ah,0ch
  233.         mov     al,0
  234.         int     21h
  235.         ret
  236. _flushk   endp
  237.  
  238. _keystat proc    near
  239.         mov     ah,0bh
  240.         int     21h
  241.         mov     ah,0
  242.         ret
  243. _keystat endp
  244.  
  245. _getime proc     near
  246.         mov     ah,2ch
  247.         int     21h
  248.         mov     _sec,dh
  249.         mov     _hsec,dl
  250.         ret
  251. _getime  endp
  252.  
  253. _cursoff proc    near
  254. ; Move the cursor to a position we have set to a background color of
  255. ; black during the game
  256.         mov     ah,02h
  257.         mov     dh,16h
  258.         mov     dl,0
  259.         mov     bh,0h
  260.         int     10h
  261.         ret
  262. _cursoff endp
  263.  
  264. _TEXT   ENDS
  265.         END
  266.